<?php
if(is_home())
	$mcat = 2;
else if(is_category())
$mcat = get_query_var('cat');
else
	return;
$root_cat = get_root_category($mcat);

//print_r($cat);
$args = array(
'title_li'=>'<span class="cate-title">Danh mục</span>',
'child_of'=>$root_cat->term_id,
'hide_empty'=>0,
'depth'=>2,
);
$yourcat = get_category($mcat);
?>
<link rel='stylesheet' id='twentytwelve-leftnavigation-css'  href='<?php echo get_template_directory_uri(); ?>/css/leftnavigation.css' type='text/css' media='all' />
<?php 
$level = 0;
get_level($yourcat, $level);
if($level>0) { 
$args_sub = array(
'title_li'=>'<span class="cate-title">'.$yourcat->cat_name.'</span>',
'child_of'=>$yourcat->cat_ID,
'depth'=>1,
'show_option_none'=>'',
'echo'=>0,
);

	
if($level == 2){
	$args_sub['child_of'] = $yourcat->category_parent;
	$catlv2 = get_category($yourcat->category_parent);
	$args_sub['title_li'] = '<span class="cate-title">'.$catlv2->cat_name.'</span>';
}
$list_sub3 = wp_list_categories($args_sub);
$regexp = "<ul>(.*)<\/ul>";
preg_match("/$regexp/siU", $list_sub3, $matches);
if($list_sub3 && $matches[1] !=''){
//nếu lv 2 thì ko show cate
$args['exclude'] = $yourcat->cat_ID;
?>
<ul class="leftnavigation-subnavigation">
	<?php echo $list_sub3;?>
</ul>
<?php }
}?>
<ul class="leftnavigationx">
	<?php wp_list_categories( $args );?>
</ul>


